/*
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "EPUB_Element.h"

EPUB_Element::EPUB_Element(EDE_Type type,
		const UT_UTF8String& value):
		m_type(type),
		m_level(0),
		m_value(value)
{
	m_name = GetNameByType(type);
}

EPUB_Element::~EPUB_Element()
{
}

EDE_Type EPUB_Element::getType() const
{
	return m_type;
}


const UT_UTF8String &EPUB_Element::getValue() const
{
	return m_value;
}

UT_GenericStringMap<UT_UTF8String*>& EPUB_Element::getAttributes()
{
	return m_attributes;
}

std::vector<EPUB_Shared_Element>& EPUB_Element::getChildren()
{
	return m_children;
}

int EPUB_Element::getLevel() const
{
	return m_level;
}

const UT_UTF8String & EPUB_Element::getName() const
{
	return m_name;
}
void EPUB_Element::setType(EDE_Type type)
{
	m_type = type;
}


void EPUB_Element::setValue(const UT_UTF8String &value)
{
	m_value = value;
}

void EPUB_Element::setAttribute(const UT_String &attribute,
		UT_UTF8String *value)
{
	m_attributes.set(attribute, value);
}

void EPUB_Element::setLevel(int level)
{
	m_level = level;

	for(int i = 0; i < m_children.size(); i++)
	{
		m_children.at(i)->setLevel(level + 1);
	}
}
void EPUB_Element::addChild(const EPUB_Shared_Element& child)
{
	m_children.push_back(child);
	child->setLevel(this->m_level + 1); // Child will have level greater by 1
}

UT_UTF8String EPUB_Element::GetNameByType(EDE_Type type)
{
	switch (type)
	{
	case EDE_Hyperlink:
		return UT_UTF8String("a");
	case EDE_Image:
		return UT_UTF8String("img");
	case EDE_Paragraph:
		return UT_UTF8String("p");
	case EDE_Span:
		return UT_UTF8String("span");
	case EDE_OrderedList:
		return UT_UTF8String("ol");
	case EDE_UnorderedList:
		return UT_UTF8String("ul");
	case EDE_ListItem:
		return UT_UTF8String("li");
	case EDE_Table:
		return UT_UTF8String("table");
	case EDE_TableRow:
		return UT_UTF8String("tr");
	case EDE_TableCell:
		return UT_UTF8String("td");
	case EDE_Html:
		return UT_UTF8String("html");
	case EDE_Head:
		return UT_UTF8String("head");
	case EDE_Body:
		return UT_UTF8String("body");
	case EDE_Title:
		return UT_UTF8String("title");
	case EDE_Div:
		return UT_UTF8String("div");
	default:
		return UT_UTF8String("");
	}
}
